package util;

import android.app.Activity;

import java.util.HashMap;
import java.util.Map;

import cn.edu.buaa.txtReader.R;

/**
 * Created by Administrator on 2016/3/9.
 */
public class Global {
    public static int SCREEN_WIDTH;
    public static int SCREEN_HEIGHT;
    //建立一个Map集合，里面封装了所有扩展名对应的图标名称，以便进行文件图标的显示
    public static Map<String, Integer> allIconImgs = new HashMap<String, Integer>();
    public static DBUtil util;

    //每行显示20个字
    public static int LINE_CHAR_COUNT=20;
    //每个文字之间的间距是2
    public static int CHAR_SEP=2;
    //左右两边页边距是20
    public static int PAGE_SEP=20;
    //行间距是2
    public static int LINE_SEP=4;
    //文字的大小
    public static int CHAR_SIZE;
    //每页显示多少行
    public static int LINE_COUNT;
    //每行结束时的标识符
    public static final String LINE_OVER_FLAG="LINE_OVER";

    public static void init(Activity a) {
        SCREEN_WIDTH = a.getWindowManager().getDefaultDisplay().getWidth();
        SCREEN_HEIGHT = a.getWindowManager().getDefaultDisplay().getHeight();

        //初始化数据
        util=new DBUtil(a);

        //初始化所有扩展名和图片的对应关系
        allIconImgs.put("txt", R.drawable.txt_file);
        allIconImgs.put("mp3", R.drawable.mp3_file);
        allIconImgs.put("mp4", R.drawable.mp4_file);
        allIconImgs.put("bmp", R.drawable.image_file);
        allIconImgs.put("gif", R.drawable.image_file);
        allIconImgs.put("png", R.drawable.image_file);
        allIconImgs.put("jpg", R.drawable.image_file);
        allIconImgs.put("dir_open", R.drawable.open_dir);
        allIconImgs.put("dir_close", R.drawable.close_dir);

        CHAR_SIZE=(SCREEN_WIDTH-PAGE_SEP*2-(LINE_CHAR_COUNT-1)*CHAR_SEP)/LINE_CHAR_COUNT;
        //占屏幕的4/5(真正文字所占的行数在包括行间距的区域内所占的比例)
        LINE_COUNT=SCREEN_HEIGHT*4/5/(CHAR_SIZE+LINE_SEP);
    }
}
